home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 109 / EnigmaAmiga109CD.iso / dalla rivista / host contacted / jikes.lha / jikes-1.11 / src / depend.h < prev    next >
C/C++ Source or Header  |  2000-01-07  |  4KB  |  142 lines

  1. // $Id: depend.h,v 1.7 2000/01/07 00:25:53 lord Exp $
  2. //
  3. // This software is subject to the terms of the IBM Jikes Compiler
  4. // License Agreement available at the following URL:
  5. // http://www.ibm.com/research/jikes.
  6. // Copyright (C) 1996, 1998, International Business Machines Corporation
  7. // and others.  All Rights Reserved.
  8. // You must accept the terms of that agreement to use this software.
  9. //
  10. #ifndef depend_INCLUDED
  11. #define depend_INCLUDED
  12.  
  13. #include "tuple.h"
  14. #include "config.h"
  15. #include <limits.h>
  16.  
  17. class Semantic;
  18. class TypeSymbol;
  19. class AstClassBody;
  20. class AstConstructorDeclaration;
  21. class SymbolSet;
  22.  
  23. class CycleChecker
  24. {
  25. public:
  26.     enum { OMEGA = -1, CYCLE_INFINITY = INT_MAX };
  27.  
  28.     inline int Min(int x, int y) { return (x < y ? x : y); }
  29. };
  30.  
  31. class TypeCycleChecker : public CycleChecker
  32. {
  33. public:
  34.  
  35.     TypeCycleChecker(Tuple<TypeSymbol *> &type_list_) : type_list(type_list_)
  36.     {}
  37.     void PartialOrder(Tuple<Semantic *> &, int);
  38.     void PartialOrder(SymbolSet &);
  39.  
  40. private:
  41.     class Stack
  42.     {
  43.     public:
  44.         void Push(TypeSymbol *type) { info.Next() = type; }
  45.         void Pop()                  { if (info.Length() > 0) info.Reset(info.Length() - 1); }
  46.         int Size()                  { return info.Length(); }
  47.         TypeSymbol *Top()           { return (TypeSymbol *) (info.Length() > 0 ? info[info.Length() - 1] : NULL); }
  48.     private:
  49.         Tuple<TypeSymbol *> info;
  50.     } stack;
  51.  
  52.     Tuple<TypeSymbol *> &type_list;
  53.  
  54.     void ProcessSubtypes(TypeSymbol *);
  55.     void ReverseTypeList();
  56. };
  57.  
  58.  
  59. class ConstructorCycleChecker : public CycleChecker
  60. {
  61. public:
  62.  
  63.     ConstructorCycleChecker(AstClassBody *);
  64.  
  65. private:
  66.     class Stack
  67.     {
  68.     public:
  69.         void Push(AstConstructorDeclaration *constructor) { info.Next() = constructor; }
  70.         void Pop()                                        { if (info.Length() > 0) info.Reset(info.Length() - 1); }
  71.         int Size()                                        { return info.Length(); }
  72.         AstConstructorDeclaration *Top()
  73.            { return (AstConstructorDeclaration *) (info.Length() > 0 ? info[info.Length() - 1] : NULL);}
  74.     private:
  75.         Tuple<AstConstructorDeclaration *> info;
  76.     } stack;
  77.  
  78.     void CheckConstructorCycles(AstConstructorDeclaration *);
  79. };
  80.  
  81.  
  82. class TypeDependenceChecker : public CycleChecker
  83. {
  84. public:
  85.     TypeDependenceChecker(Control *control_, SymbolSet &file_set_, Tuple<TypeSymbol *> &type_trash_bin_)
  86.         : file_set(file_set_),
  87.           control(control_),
  88.           type_trash_bin(type_trash_bin_)
  89.     {}
  90.  
  91.     ~TypeDependenceChecker() {}
  92.  
  93.     void PartialOrder();
  94.     void OutputDependences();
  95.  
  96.     Tuple<TypeSymbol *> &TypeList() { return type_list; }
  97.  
  98.     SymbolSet &file_set;
  99.  
  100. private:
  101.     Control *control;
  102.     Tuple<TypeSymbol *> &type_trash_bin;
  103.  
  104.     class Stack
  105.     {
  106.     public:
  107.         void Push(TypeSymbol *type) { info.Next() = type; }
  108.         void Pop()                  { if (info.Length() > 0) info.Reset(info.Length() - 1); }
  109.         int Size()                  { return info.Length(); }
  110.         TypeSymbol *Top()           { return (TypeSymbol *) (info.Length() > 0 ? info[info.Length() - 1] : NULL); }
  111.     private:
  112.         Tuple<TypeSymbol *> info;
  113.     } stack;
  114.  
  115.     void OutputMake(FILE *, char *, Tuple<FileSymbol *> &);
  116.     void OutputMake(FileSymbol *);
  117.  
  118.     Tuple<TypeSymbol *> type_list;
  119.  
  120.     void ProcessType(TypeSymbol *);
  121. };
  122.  
  123.  
  124. class TopologicalSort
  125. {
  126. public:
  127.     TopologicalSort(SymbolSet &, Tuple<TypeSymbol *> &);
  128.     ~TopologicalSort();
  129.  
  130.     void Sort();
  131.  
  132. private:
  133.     void Process(TypeSymbol *);
  134.  
  135.     SymbolSet *pending;
  136.  
  137.     SymbolSet &type_collection;
  138.     Tuple<TypeSymbol *> &type_list;
  139. };
  140.  
  141. #endif /* cycle_INCLUDED */
  142.